<template>
  <div>
    <div class="nav">
      <div class="search">
        <van-icon name="arrow-left" />
        <input type="text" placeholder="输入搜索内容" />
        <span>搜索</span>
      </div>
    </div>

    <div class="bot">
      <h3>为你推荐</h3>
      <div class="recommended">
        <router-link
          tag="div"
          class="item"
          v-for="item in productList"
          :key="item.id"
          :to="{path:'/detail',query:{id:item.id}}"
        >
          <div class="top">
            <img :src="item.picture" alt />
          </div>
          <div class="cen">
            <p class="title">{{item.product}}</p>
            <p class="detail">{{item.detail}}</p>
          </div>
          <div class="bot">
            <div class="lef">
              <span class="price">￥{{item.price}}</span> |
              <span class="oldprice">{{item.oldprice}}</span>
            </div>
            <div class="rig">
              <van-icon name="shopping-cart-o" @click.stop="addToCart(item.id)" />
            </div>
          </div>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "Serach",
  data()
  created(){
    request
      .get(
        `api/shop/list/category?categoryId=${Math.floor(Math.random() * 6 + 1)}`
      )
      .then(data => {
        this.productList = data.list;
      });
  }
};
</script>

<style lang="less" scoped>
.search,
.nav {
  width: 100%;
  display: flex;
  justify-content: space-between;
  .search {
    line-height: 30px;
    margin-top: 10px;

    input {
      width: 80%;
      outline: none;
      border-radius: 15px;
    }
    .van-icon,
    span {
      width: 15%;
      line-height: 30px;
      text-align: center;
    }
  }
}
</style>
